package com.lw.edu.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lw.commonutil.result.Result;
import com.lw.edu.entity.Course;
import com.lw.edu.entity.Teacher;
import com.lw.edu.service.CourseService;
import com.lw.edu.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/edu/teacher")
public class TeacherApiController {
    @Autowired
    private TeacherService teacherService;
    @Autowired
    private CourseService courseService;

    //分页查询讲师
    @GetMapping("/getPageList/{page}/{limit}")
    public Result getPageList(@PathVariable Long page,@PathVariable Long limit){
        Page<Teacher> pageTeacher = new Page<>(page,limit);
        Map<String,Object> map = teacherService.getPageList(pageTeacher);
        return Result.ok( map );
    }
    //讲师详情和讲师所拥有的课程信息
    @GetMapping("{id}")
    public Result getTeacher(@PathVariable String id){
        Teacher teacher = teacherService.getById( id );
        QueryWrapper<Course> wrapper = new QueryWrapper<>();
        wrapper.eq( "teacher_id",id );
        List<Course> courseList = courseService.list( wrapper );
        Map<String,Object> map = new HashMap<>();
        map.put( "teacher",teacher );
        map.put( "courseList",courseList );
        return Result.ok(map);
    }
}
